package light.head.dao.sys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.model.RoleMain;
import light.head.model.RoleMainPK;

import org.springframework.stereotype.Service;

/**
 * 角色对应的默认管理页面
 */
@Service
public class RoleMainDAO extends BaseDAO<RoleMain, RoleMainPK> {
	
	private final static String sql_findToMap = "FROM RoleMain rm WHERE rm.rc = ?";
	private final static String sql_delByRoleCode = "DELETE FROM RoleMain WHERE rc = ?";
	
	/**
	 * 根据角色编号获取角色相应的默认页面对象，并封装到Map中
	 * @param	角色编号
	 */
	public Map<String, Boolean> findToMap(Integer code) {
		
		List<RoleMain> list = find(sql_findToMap, code);
		if (null != list && list.size() > 0) {
			Map<String, Boolean> map = new HashMap<String, Boolean>();
			for (RoleMain rm : list) {
				map.put(rm.getTc().toString(), true);
			}
			return map;
		}
		return null;
	}
	
	/**
	 * 根据角色编号删除相关的所有RoleMain对象
	 * @param	角色编号
	 */
	public RESULT delByRoleCode(Integer code) {
		if (null == code)
			return RESULT.PARAMETER_ERROR;
		
		execute(sql_delByRoleCode, code);
		return RESULT.SUCCESS;
	}
}
